//
//  MainVC+Noti.swift
//  MedicalUnionHybrid
//
//  Created by 来 on 2019/9/23.
//  Copyright © 2019 EWell. All rights reserved.
//

import Foundation

let NOTI_SHOW_TAB_BAR = NSNotification.Name(rawValue: "EWEShowTabBar")

let NOTI_HIDE_TAB_BAR = NSNotification.Name(rawValue: "EWEHideTabBar")

extension MainVC {

    // 添加通知
    func addNotification() {
        NotificationCenter.default.addObserver(self, selector: #selector(showTabBar(_:)), name: NOTI_SHOW_TAB_BAR, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(hideTabBar(_:)), name: NOTI_HIDE_TAB_BAR, object: nil)
    }
    
    @objc func showTabBar(_ notification: Notification!) {
        childVCSV.snp.updateConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 0, left: 0, bottom: UIDevice.lgf_TabBarH(), right: 0))
        }
        UIView.animate(withDuration: 0.35) {
            self.childVCSV.superview!.layoutIfNeeded()
            self.tabBar.transform = CGAffineTransform.identity
        }
    }
    
    @objc func hideTabBar(_ notification: Notification!) {
        childVCSV.snp.updateConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 0))
        }
        UIView.animate(withDuration: 0.35) {
            self.childVCSV.superview!.layoutIfNeeded()
            self.tabBar.transform = CGAffineTransform.init(translationX: 0, y: self.tabBar.lgf_Height + (UIDevice.lgf_IsIphoneX() ? 22.0 : 0.0) + 10)
        }
    }
    
}
